# 
# Given two sorted integer arrays A and B, merge B into A as one sorted array.
# Note:
# You may assume that A has enough space (size that is greater or equal to m + n) 
# to hold additional elements from B. The number of elements initialized in A and 
# B are m and n respectively.
#

# @author:timlentse(tinglenxan@gmail.com)
# @Date:2014-11-19

    # @param A  a list of integers
    # @param m  an integer, length of A
    # @param B  a list of integers
    # @param n  an integer, length of B
    # @return merged array A
def merge( A, m, B, n):
    lastIndexOfA ,lastIndexOfB = m-1,n-1
    indexToBeWritten = m+n-1
    while(lastIndexOfA!=-1)and(lastIndexOfB!=-1):
        if A[lastIndexOfA]>B[lastIndexOfB]:
            A[indexToBeWritten] = A[lastIndexOfA]
            lastIndexOfA -= 1
            indexToBeWritten -= 1
        else:
            A[indexToBeWritten] = B[lastIndexOfB]
            lastIndexOfB -=1
            indexToBeWritten -= 1
    if lastIndexOfB >-1: A[:lastIndexOfB+1] = B[:lastIndexOfB+1]
    return A
A = [1,0]
B = [2]
print merge(A,1,B,1)       
            